package com.ang.quartz.springboot.controller;

import com.fasterxml.jackson.databind.util.JSONPObject;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ssang
 * @date 2022-01-07 9:55
 */
@RestController
public class TestController {

    @Autowired
    JobDetail jobDetail;
    @Autowired
    Trigger trigger;

    @RequestMapping("/test")
    public JSONPObject test(){
        JSONPObject jsonpObject = new JSONPObject("1","ang");
        return jsonpObject;
    }

    @RequestMapping("/addJob")
    public void addJob() throws Exception{
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();

        scheduler.scheduleJob(jobDetail,trigger);
        scheduler.start();
    }
}
